Ext.define('ES.controller.archives.ArchivesController',{
	extend:'Ext.app.Controller',
	 views: [
        'archives.Archives',
        'archives.DashBoard'
    ],
    refs: [
        {
        	ref:'archivesCompRef',
        	selector:'archivescomp'
        },
        {
        	ref:'dashboardRef',
        	selector:'dashboard'
        }
    ],
    requires:['ES.store.component.CompCategoryStore','ES.view.archives.Archives','ES.store.archives.ArchivesStore','ES.model.archives.ArchivesModel','ES.view.archives.DashBoard'],
    stores:['component.CompCategoryStore','ES.store.archives.ArchivesStore'],
    models:['ES.model.archives.ArchivesModel'],
	init:function(){
		this.control({
			'archivescomp':{
				afterrender:this.archivescompRendered
			},
			'dashboard':{
				afterrender:this.dashboardRendered
			}
		});
	},
    archivescompRendered: function(aComp) {
    	var me = this;
		aComp.loadTree(this.getStore('component.CompCategoryStore'));
		this.getStore('archives.ArchivesStore').each(function(result){
			aComp.loadProfileData(result);
		})
    },
    dashboardRendered:function(dashboard){
    	dashboard.down('customcombo[name=projects]').on('selectitem',this.onProjectChange);
    },
    onProjectChange: function(proCombo,record){
    	Ext.ComponentQuery.query('dashboard')[0].updateProjectDashboard(record);
    }
});